package com.lin.controller.user.musicstand;


import com.lin.common.result.PageResult;
import com.lin.common.result.Result;
import com.lin.entity.MusicCategory;
import com.lin.entity.Search;
import com.lin.entity.dto.MusicDTO;
import com.lin.entity.vo.MusicVO;
import com.lin.service.MusicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/music")
@Api(tags = "谱架相关接口")
@Slf4j
public class MusicController {


    @Autowired
    private MusicService musicService;

    /**
     * 获取谱架分类
     * @return
     */
    @GetMapping("/category")
    @ApiOperation("获取谱架分类")
    public Result<List<MusicCategory>> getCategory(){
        log.info("获取谱架分类...");
        List<MusicCategory> list = musicService.getCategory();
        return Result.success(list);
    }

    /**
     * 获取每日推荐
     * @return
     */
    @GetMapping("/recommend")
    @ApiOperation("获取每日推荐")
    public Result<List<MusicVO>> getRecommend(){
        log.info("获取每日推荐...");
        List<MusicVO> musicList = musicService.getRecommend();
        return Result.success(musicList);
    }

    /**
     * 按条件分页查询
     * @param musicDTO
     * @return
     */
    @GetMapping
    @ApiOperation("按条件分页查询")
    public Result<PageResult> getMusic(MusicDTO musicDTO){
        log.info("按条件分页查询: {}",musicDTO);
        PageResult pageResult = musicService.getMusic(musicDTO);
        return Result.success(pageResult);
    }

    /**
     * 获取乐谱详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation("获取乐谱详情")
    public Result<MusicVO> getMusicDetail(@RequestParam Integer id){
        log.info("获取乐谱详情 : {}",id);
        MusicVO musicVO = musicService.getMusicDetail(id);
        return Result.success(musicVO);
    }

    /**
     * 获取用户的搜索历史
     * @param userId
     * @return
     */
    @GetMapping("/Recording")
    @ApiOperation("获取用户的搜索历史")
    public Result<List<Search>> getSearchByUserId(@RequestParam("userId") Integer userId){
        log.info("获取用户的搜索历史 ：{}",userId);
        List<Search> searches = musicService.getSearchByUserId(userId);
        return Result.success(searches);
    }

    /**
     * 获取热门搜索
     * @return
     */
    @GetMapping("/popular")
    @ApiOperation("获取热门搜索")
    public Result<List<String>> getPopularSearches(){
        log.info("获取热门搜索...");
        List<String> stringList = musicService.getPopularSearches();
        return Result.success(stringList);
    }

    /**
     * 删除用户搜索记录
     * @param search
     * @return
     */
    @DeleteMapping("/search")
    @ApiOperation("删除用户搜索记录")
    public Result deleteSearch(@RequestBody Search search){
        log.info("删除用户搜索记录:{}",search);
        musicService.deleteSearch(search);
        return Result.success();
    }
}
